package com.eric.husky.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;
import com.eric.husky.common.CommonController;
import com.eric.husky.common.web.ResponseModel;
import com.eric.husky.bean.Position;
import com.eric.husky.service.PositionService;
import java.util.List;

@RequestMapping(value = "/position")
@RestController
@Api(value="位置管理接口",tags={"Position(位置管理)-增删改查;导入导出"})
public class PositionController extends CommonController{

	@Autowired
	private PositionService positionService;

	@ApiOperation(value = "获取分页数据" ,notes = "获取分页数据" )
    @GetMapping("/list")
    public Page<Position> list(Position position, Pageable page) {
        return positionService.list(position, page);
    }

    @ApiOperation(value = "获取列表数据" ,notes = "获取列表数据" )
	@GetMapping("/findAll")
	public List<Position> findAll(){
		return positionService.findList();
	}

    @ApiOperation(value = "获取单条数据对象" ,notes = "获取单条数据对象")
	@ApiImplicitParams({
		@ApiImplicitParam(paramType = "query",name = "positionid" ,value = "positionID" , required = true, dataType = "Integer")
	})
	@GetMapping("/{locationid}")
    public Position get(@PathVariable Integer locationid) {
		return positionService.get(locationid);
    }

    @ApiOperation(value = "保存单条数据", notes = "保存单条数据,id列为空则为新增,不为空则为修改")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "Position",value = "position",required = false,dataType = "Position")
    })
    @PostMapping("/save")
    public Position save(@RequestBody Position position) {
		return positionService.save(position);
    }

    @ApiOperation(value = "删除位置管理", notes = "删除位置管理" )
    @ApiImplicitParams({ @ApiImplicitParam(name = "positionids", value = "PositionID", required = true, dataType = "String")
    })
    @RequestMapping(value = "/delete" ,method = { RequestMethod.DELETE})
    public ResponseModel delete(String positionids) {
        try {
            String[] id_array = positionids.split(",");
            for(String positionid:id_array){
                positionService.delete(Integer.parseInt(positionid));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseModel.success("删除成功");
    }

}